]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
animation: Load sliced image using resource scale, and reload on change
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 30 Nov 2017 01:36:05 +0000 (02:36 +0100)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 1 Mar 2019 17:12:53 +0000 (17:12 +0000)
Also make sure that the textures size is matching the container size.

https://bugzilla.gnome.org/show_bug.cgi?id=765011

js/ui/animation.js

index 470a6ffbbfeaa15054d6338c7304eae4dc7f4a47..0d711567fdfcd957077dae355bfd81017bb8b3a7 100644 (file)
@@ -12,7 +12,12 @@ var SPINNER_ANIMATION_DELAY = 1.0;
 var Animation = class {
     constructor(file, width, height, speed) {
         this.actor = new St.Bin();
+        this.actor.set_size(width, height);
         this.actor.connect('destroy', this._onDestroy.bind(this));
+        this.actor.connect('notify::size', this._syncAnimationSize.bind(this));
+        this.actor.connect('resource-scale-changed',
+            this._loadFile.bind(this, file, width, height));
+
         this._speed = speed;
 
         this._isLoaded = false;
@@ -20,10 +25,7 @@ var Animation = class {
         this._timeoutId = 0;
         this._frame = 0;
 
-        let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
-        this._animations = St.TextureCache.get_default().load_sliced_image (file, width, height, scaleFactor,
-                                                                            this._animationsLoaded.bind(this));
-        this.actor.set_child(this._animations);
+        this._loadFile(file, width, height);
     }
 
     play() {
@@ -47,6 +49,23 @@ var Animation = class {
         this._isPlaying = false;
     }
 
+    _loadFile(file, width, height) {
+        let [validResourceScale, resourceScale] = this.actor.get_resource_scale();
+
+        this._isLoaded = false;
+        this.actor.destroy_all_children();
+
+        if (!validResourceScale)
+            return;
+
+        let texture_cache = St.TextureCache.get_default();
+        let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
+        this._animations = texture_cache.load_sliced_image(file, width, height,
+                                                           scaleFactor, resourceScale,
+                                                           this._animationsLoaded.bind(this));
+        this.actor.set_child(this._animations);
+    }
+
     _showFrame(frame) {
         let oldFrameActor = this._animations.get_child_at_index(this._frame);
         if (oldFrameActor)
@@ -64,9 +83,21 @@ var Animation = class {
         return GLib.SOURCE_CONTINUE;
     }
 
+    _syncAnimationSize() {
+        if (!this._isLoaded)
+            return;
+
+        let [width, height] = this.actor.get_size();
+
+        for (let i = 0; i < this._animations.get_n_children(); ++i)
+            this._animations.get_child_at_index(i).set_size(width, height);
+    }
+
     _animationsLoaded() {
         this._isLoaded = this._animations.get_n_children() > 0;
 
+        this._syncAnimationSize();
+
         if (this._isPlaying)
             this.play();
     }